package com.mrd.gtimp.business.service;

import com.mrd.base.BaseBiz;
import com.mrd.gtimp.business.entity.DeclaRejectCount;
import com.mrd.gtimp.business.repository.DeclaRejectCountDao;
import com.mrd.spring.repository.BaseRepository;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Date;

import javax.annotation.Resource;

/**
 * Created by dark on 17/7/14.
 */
@Service
public class DeclaRejectCountBiz extends BaseBiz<DeclaRejectCount> {
    @Override
    @Resource
    @Qualifier("declaRejectCountDao")
    public void setBaseRepository(BaseRepository<DeclaRejectCount, String> baseRepository) {
        this.baseRepository = baseRepository;
    }

    @Resource
    private DeclaRejectCountDao declaRejectCountDao;

    /**
     * 根据报关单ID初始化驳回记录
     */
    public void initDeclaRejectCount(String declaID, String uid) throws Exception {
        if (StringUtils.isEmpty(declaID) || StringUtils.isEmpty(uid)) {
            throw new Exception("");
        }
        DeclaRejectCount declaRejectCount = new DeclaRejectCount();
        declaRejectCount.setId(null);
        declaRejectCount.setCount(1);
        declaRejectCount.setCreateTime(new Date());
        declaRejectCount.setCreator(uid);
        this.saveOrupdateEntity(declaRejectCount);
    }

    /**
     * 增加驳回次数记录
     */
    public void addDeclaRejectCount(String declaID, String uid) throws Exception {
        if (StringUtils.isEmpty(declaID) || StringUtils.isEmpty(uid)) {
            throw new Exception("");
        }
//        List<DeclaRejectCount> list = declaRejectCountDao.findByDeclaId(declaID);
//        if (CollectionUtils.isNotEmpty(list) && list.size() == 1) {
//            DeclaRejectCount declaRejectCount = list.get(0);
//            declaRejectCount.setCount(declaRejectCount.getCount() + 1);
//            declaRejectCount.setModifier(user.getId());
//            declaRejectCount.setModifyTime(new Date());
//            this.saveOrupdateEntity(declaRejectCount);
//        } else {
//            throw new Exception("");
//        }
    }
}
